package com.yan.demo.method;
// 无参无返回值
public class MethodDemo2 {
    public static void main(String[] args) {
        printAvg();
        printInversion();
    }

    public static void printAvg() {
        int[] arr = {1, 2, 3, 4, 5};
        double sum = 0.0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];
        }
        System.out.println("平均值为" + sum / arr.length);
    }

    public static void printInversion() {
        int[] arr = {1, 2, 3, 4, 5};
       /* for (int start = 0 , end = arr.length - 1; start < end; start++ , end--) {
            int temp;
            temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }*/
        for (int i = 0; i < (arr.length - 1) / 2; i++) {
            int temp;
            temp = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
        }
        print(arr);
    }

    public static void print(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + " ");
            }
        }
        System.out.print("]");
    }

}
